﻿namespace Singleton.Sample.Implementations
{
    /// <summary>
    /// PS: Keyword "sealed" is used for JIT optimizations
    /// PS 2: This class uses a critical zone to solve the concurrent memory-barrier issue.
    /// </summary>
    public sealed class Singleton_2_SimpleThreadSafe
    {
        private static Singleton_2_SimpleThreadSafe instance = null;
        private static readonly object syncRoot = new object();

        Singleton_2_SimpleThreadSafe() { }

        public static Singleton_2_SimpleThreadSafe Instance
        {
            get
            {
                lock (syncRoot)
                {
                    if (instance == null)
                    {
                        instance = new Singleton_2_SimpleThreadSafe();
                    }
                    return instance;
                }
            }
        }
    }
}